cmake_minimum_required(VERSION 3.16)

project(benchmarkfloat LANGUAGES CXX)

if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
    set(CMAKE_CXX_STANDARD 23)
else()
    set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(OpenMP REQUIRED)

include_directories(${PROJECT_SOURCE_DIR}/3rdparty/simde)

add_executable(benchmarkfloat
  main.cpp
)
target_link_libraries(benchmarkfloat PUBLIC OpenMP::OpenMP_CXX
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
      set(CMAKE_CXX_FLAGS_RELEASE -fopenmp-simd)
  endif()
  if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0)
      add_definitions(-DUSE_QUADMATH=1)
      target_link_libraries(benchmarkfloat PUBLIC libquadmath)
  endif()
endif()

include(GNUInstallDirs)
install(TARGETS benchmarkfloat
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_RELEASE -Ofast)

# set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -O3  -Wall")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3  -Wall")

add_definitions(-DFP_FAST_FMA=1 -DFP_FAST_FMAF=1 -DFP_FAST_FMAL=1)
add_definitions(-D__STDC_WANT_IEC_60559_TYPES_EXT__=1)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
        message(STATUS "GCC version is less than 13.0")
    elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
        message(STATUS "GCC version is less than 9.0")
    elseif(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 9.0)
        message(STATUS "GCC version is 9.0")
    else()
        message(STATUS "GCC version is greater than 9.0")
    endif()
else()
    message(STATUS "Not using GNU GCC")
endif()

